import Pool from './base/pool'
import {PageStatus} from "./page_status";
import {winW} from "./libs/utils";

let instance

const leftRouteVenue = [[0,"三沙Left"],[1,"海南"],[2,"广东"],[3,"澳门"],[4,"香港"],[5,"台湾"],[6,"福建"],[7,"浙江"],[8,"上海"],[9,"江苏"],[10,"山东"],[11,"天津"],[12,"辽宁"],[13,"吉林"],[14,"黑龙江"],[1000,"漠河"],];
const centerRouteVenue = [[0,"三沙Center"],[1,"海南"],[2,"广东"],[3,"澳门"],[4,"香港"],[5,"台湾"],[6,"福建"],[7,"浙江"],[8,"上海"],[9,"江苏"],[10,"山东"],[11,"天津"],[12,"辽宁"],[13,"吉林"],[14,"黑龙江"],[1000,"漠河"],];
const rightRouteVenue = [[0,"三沙"],[1,"海南"],[2,"广东"],[3,"澳门"],[4,"香港"],[5,"台湾"],[6,"福建"],[7,"浙江"],[8,"上海"],[9,"江苏"],[10,"山东"],[11,"天津"],[12,"辽宁"],[13,"吉林"],[14,"黑龙江"],[1000,"漠河"],];

/**
 * 全局状态管理器
 */
export default class DataBus {
  constructor() {
    if (instance) return instance

    instance = this

    this.pool = new Pool()

    this.reset()
    this.lines = 'right';

    this.routeIndex = 2; /// 默认走西线
  }


  setLines(lines){
    this.lines = lines;
    /// 写入缓存
  }
  getLines(lines){
    ///读取缓存

  }
  reset() {
    this.frame = 0
    this.score = 0
    this.gameOver = false
    this.gameStatus = PageStatus.GameIntroduce


    /**
     * 确定了左右间隙，需要为整数，不然边框有问题
     */
    this.gap = 20   //左边间隙20像素
    this.backgroundLong = 10   //横竖都是十行
    this.backgroundWidth = 10
    this.stepx = (winW - 40) / this.backgroundWidth   //每一格子的大小=屏幕宽度-40 除以 格子数
    this.stepx = Math.round(this.stepx)
    this.stepy = this.stepx
    this.gap = (winW - this.stepx * this.backgroundWidth) / 2
    this.gap = Math.round(this.gap)
    this.gapRight = winW - this.gap - this.backgroundWidth * this.stepx
  }
  getAllVenue(route){
    switch (route){
      case 0:
        return leftRouteVenue;
      case 1:
        return centerRouteVenue;
      default:
        return rightRouteVenue;
    }
  }


}